<template>
  <!-- 玩家活动领取记录 -->
  <div class="app-container">
    <div class="app-wrap">
      <search-table ref="table" :table-loading="listLoading" :table-data="goldDataList" @query="getGoldList(true)" @reset="refresh">
        <template v-slot:row>
          <el-form-item label="日期时间:" label-width="80px">
            <el-date-picker is-range v-model="listQuery.dateTime" type="datetimerange" range-separator="至" start-placeholder="开始日期" 
            end-placeholder="结束日期" class="full-width-input time-box" :default-time="['00:00:00', '23:59:59']" :clearable="true"/>
          </el-form-item>
          <el-form-item label="活动类型:" label-width="80px">
            <el-select v-model="listQuery.reason" placeholder="请选择活动类型" filterable>
              <el-option label="全部" value="" ></el-option>
              <el-option v-for="(item,index) in reasonDataList" :key="index" :label="item.label" :value="item.value" ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="货币类型:" label-width="80px">
            <el-select v-model="listQuery.amount_type" placeholder="请选择货币类型" filterable>
              <el-option v-for="(item,index) in GAME_CURRENCY_TYPE" :key="index" :label="item.label" :value="item.value" ></el-option>
            </el-select>
          </el-form-item>
            <el-form-item label="用户ID:" label-width="60px">
            <el-input type="text" v-model="listQuery.user_id" clearable placeholder="请输入用户ID"></el-input>
          </el-form-item>
        </template>
        <template v-slot:actions >
          <el-button type="info" size="mini" icon="el-icon-refresh" @click="getGoldList" style="margin-top:-1px">刷新</el-button>
        </template>
        <template>
          <el-table-column prop="user_id" label="用户ID" align="center" width="120"/>
          <el-table-column prop="nick_name" label="用户昵称" align="center" width="200" show-overflow-tooltip/>
          <el-table-column prop="account_type" label="账户类型" align="center" width="120">
            <template slot-scope="scope">
              <el-tag :type="accountTag(scope.row.account_type)">{{ accountType(scope.row.account_type)}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="amount_type" label="货币类型" align="center" width="120">
            <template slot-scope="scope">
              <span>{{ amountType(scope.row.amount_type)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="count" label="领取次数" align="center" width="120"/>
          <el-table-column prop="reason" label="活动类型" align="center">
            <template slot-scope="scope">
              <span>{{ reasonType(scope.row.reason)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="operation" label="操作" align="center" width="100" fixed="right">
            <template slot-scope="scope">
              <el-tooltip effect="dark" content="跳转详情" placement="top-start">
                <el-button size="mini" type="primary" @click.stop="lookDetails(scope.row)" icon="el-icon-tickets" />
              </el-tooltip>
            </template>
          </el-table-column>
        </template>
        <template v-slot:footer>
          <pagination :total="currentTotal" :page.sync="listQuery.page" :limit.sync="listQuery.size" @pagination="getGoldList" />
        </template>
      </search-table>
    </div>
  </div>
</template>

<script>
import {
  throttle
} from '@/utils/index'
import {
  currencyReason,
  getActivityRecords
} from '@/api/player'
import {
  ACCOUNT_TYPE,
  GAME_CURRENCY_TYPE,
} from '@/utils/enum'

import SearchTable from '@/components/SearchTable'
export default {
  name: 'activity',
  components: {
    SearchTable
  },
  data () {
    return {
      ACCOUNT_TYPE,
      GAME_CURRENCY_TYPE,
      listQuery: {
        page: 1,
        size: 50,
        user_id:'',
        reason:'',
        amount_type:'',
        dateTime: [this.$public.getDateDay(0)+' 00:00:00',this.$public.getDateDay(0)+' 23:59:59'],
        start_time: '',
        end_time: '',
      },
      listLoading: true,
      currentTotal: 0,
      goldDataList: [],
      reasonDataList: [
        {label:'充值',value:6},
        {label:'邮件改变',value:7},
        {label:'周礼包',value:8},//领取
        {label:'周礼包',value:9},//购买
        {label:'流水返现',value:15},
        {label:'VIP升级',value:16},//奖励
        {label:'提现',value:17},
        {label:'首充直接',value:31},//领取
        {label:'首充每日',value:32},//领取
        {label:'绑定有礼',value:33},
        {label:'下载有礼',value:34},//领取
        {label:'拼多多',value:35},//奖励
        {label:'次日',value:36},//领取
        {label:'贴身服务',value:37},//领取
        {label:'7日登录',value:38},
        {label:'充值轮盘',value:39},
        {label:'月卡领取',value:40},
        {label:'月卡立即获得',value:41},
      ],
    }
  },
  created () {
    // this.getGoldList()
  },
  activated () {
    this.channelData=this.$store.state.commonState.channelDataArray
    this.getGoldList()
  },
  methods: {
    // 获取货币变动列表
    async getGoldList (query) {
      let that = this,params=that.listQuery;
      if(query && !query.page){
        params.page=1
        params.size=50
      }
      that.goldDataList = []
      if (params.dateTime && params.dateTime[0] && params.dateTime[1]) {
        params.start_time = that.$public.standardDate(params.dateTime[0])
        params.end_time = that.$public.standardDate(params.dateTime[1])
      }else{
        params.start_time = ''
        params.end_time = ''
      }
      const response = await getActivityRecords(params)
      if (response.code == 1) {
        if(response.data.list){
          that.goldDataList = response.data.list
          that.currentTotal = response.data.total
        }
      }else{
        that.$message.error(response.msg)
      }
      that.listLoading = false
    },
    // 查看详情
    lookDetails(row){
      this.$router.push({ 
        path: '/wander',
      })
    },
    // 账号类型展示
    accountType(cellValue){
      return (this.ACCOUNT_TYPE.find((item) => item.value === cellValue)?.label || "测试账号");
    },
    // 账号类型展示
    accountTag(cellValue){
      return (this.ACCOUNT_TYPE.find((item) => item.value === cellValue)?.type || "-");
    },
    // 货币类型
    amountType(cellValue){
      return (this.GAME_CURRENCY_TYPE.find((item) => item.value === cellValue)?.label || "-");
    },
    // 变动原因
    reasonType(cellValue){
      return (this.reasonDataList.find((item) => item.value === cellValue)?.label || "-");
    },
    // 刷新
    refresh: throttle(function () {
      this.listQuery = {
        page: 1,
        size: 50,
        user_id:'',
        reason:'',
        amount_type:'',
        dateTime: [this.$public.getDateDay(0)+' 00:00:00',this.$public.getDateDay(0)+' 23:59:59'],
        start_time: '',
        end_time: '',
      }
      this.getGoldList()
    }, 2000),
  }
}
</script>

<style lang="scss" scoped>
.nameInfo {
  color: #409EFF;
  padding-bottom: 2px;
  border-bottom:1px solid #409EFF;
  cursor: pointer;
}
</style>
